package com.jwgf.smarowindingmachine_unity.logic;

import com.jwgf.common.AppContext;
import com.jwgf.common.DataAccessRule;
import com.jwgf.smarowindingmachine_unity.R;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Set;

public class SmaroWindingMachineDataAccessRules {

    // For database
    public static final String COL_TIME = "datatime";
    public static final String COL_NAME = "name";
    public static final String COL_CATEGORY = "category";

    private HashMap<String, DataAccessRule> ruleMap;
    private Set<String> keySet;
    private HashMap<String, Integer> nameMap;
    private HashMap<String, Integer> unitMap;
    private static SmaroWindingMachineDataAccessRules rules = new SmaroWindingMachineDataAccessRules();
    private MachineParameterSharedPreference sp = MachineParameterSharedPreference.getInstance();

    private SmaroWindingMachineDataAccessRules() {
        ruleMap = new LinkedHashMap<String, DataAccessRule>();

        ruleMap.put(MachineParameterSharedPreference.SYSTEM_MACHINE_NUM,
                new DataAccessRule(MachineParameterSharedPreference.SYSTEM_MACHINE_NUM,
                        DataAccessRule.INT_TYPE, 1, 999, 1));
        ruleMap.put(MachineParameterSharedPreference.SYSTEM_SERIAL_NUM,
                new DataAccessRule(MachineParameterSharedPreference.SYSTEM_SERIAL_NUM,
                        DataAccessRule.STRING_TYPE, 00000001, 99999999, 00000001));
        ruleMap.put(MachineParameterSharedPreference.SYSTEM_MACHINE_UNLOCK,
                new DataAccessRule(MachineParameterSharedPreference.SYSTEM_MACHINE_UNLOCK,
                        DataAccessRule.INT_TYPE, 0, 9999, 0));

        ruleMap.put(MachineParameterSharedPreference.MACHINE_CYCLE_NUM,
                new DataAccessRule(MachineParameterSharedPreference.MACHINE_CYCLE_NUM,
                        DataAccessRule.INT_TYPE, 0, 20, 0));
        ruleMap.put(MachineParameterSharedPreference.MACHINE_INTERVAL_TIME,
                new DataAccessRule(MachineParameterSharedPreference.MACHINE_INTERVAL_TIME,
                        DataAccessRule.INT_TYPE, 0, 20, 0));
        ruleMap.put(MachineParameterSharedPreference.MACHINE_MINUS_PRESSURE,
                new DataAccessRule(MachineParameterSharedPreference.MACHINE_MINUS_PRESSURE,
                        DataAccessRule.INT_TYPE, 30, 65, 45));
        ruleMap.put(MachineParameterSharedPreference.MACHINE_TIMES,
                new DataAccessRule(MachineParameterSharedPreference.MACHINE_TIMES,
                        DataAccessRule.INT_TYPE, 1, 5, 1));
        ruleMap.put(MachineParameterSharedPreference.MACHINE_TIME,
                new DataAccessRule(MachineParameterSharedPreference.MACHINE_TIME,
                        DataAccessRule.FLOAT_TYPE, 0.1f, 10.0f, "1", 0.1f));
        ruleMap.put(MachineParameterSharedPreference.MACHINE_PULL_FORK_OFF_TIME,
                new DataAccessRule(MachineParameterSharedPreference.MACHINE_PULL_FORK_OFF_TIME,
                        DataAccessRule.INT_TYPE, 0, 120, 15));
        ruleMap.put(MachineParameterSharedPreference.MACHINE_PULL_FORK_ON_TIME,
                new DataAccessRule(MachineParameterSharedPreference.MACHINE_PULL_FORK_ON_TIME,
                        DataAccessRule.INT_TYPE, 5, 300, 30));
        ruleMap.put(MachineParameterSharedPreference.MACHINE_EMPTY_TUBE_BELT_TRANSPORT_TYPE,
                new DataAccessRule(MachineParameterSharedPreference.MACHINE_EMPTY_TUBE_BELT_TRANSPORT_TYPE,
                        DataAccessRule.INT_TYPE, 0, 1, 0));
        ruleMap.put(MachineParameterSharedPreference.MACHINE_EMPTY_TUBE_BELT_ACTION_INTERVAL,
                new DataAccessRule(MachineParameterSharedPreference.MACHINE_EMPTY_TUBE_BELT_ACTION_INTERVAL,
                        DataAccessRule.INT_TYPE, 60, 300, 180));


        ruleMap.put(MachineParameterSharedPreference.IN_SEGMENT_CONICITY,
                new DataAccessRule(MachineParameterSharedPreference.IN_SEGMENT_CONICITY,
                        DataAccessRule.INT_TYPE, 0, 4, 3));
        ruleMap.put(MachineParameterSharedPreference.IN_SEGMENT_DIAMETER,
                new DataAccessRule(MachineParameterSharedPreference.IN_SEGMENT_DIAMETER,
                        DataAccessRule.INT_TYPE, 1, 94, 94));
        ruleMap.put(MachineParameterSharedPreference.IN_SEGMENT_TRAVERSE,
                new DataAccessRule(MachineParameterSharedPreference.IN_SEGMENT_TRAVERSE,
                        DataAccessRule.INT_TYPE, 1, 152, 152));
        ruleMap.put(MachineParameterSharedPreference.CURRENT_SPINDLE_NUMBER,
                new DataAccessRule(MachineParameterSharedPreference.CURRENT_SPINDLE_NUMBER,
                        DataAccessRule.INT_TYPE, 1, 72, 1));

        ruleMap.put("D0400", new DataAccessRule("D0400", DataAccessRule.INT_TYPE, 0, 1, 0));
        ruleMap.put("D0401", new DataAccessRule("D0401", DataAccessRule.INT_TYPE, 0, 2, 0));
        ruleMap.put("D0402", new DataAccessRule("D0402", DataAccessRule.INT_TYPE, 0, 1, 0));
        ruleMap.put("D0403", new DataAccessRule("D0403", DataAccessRule.INT_TYPE, 1, 40, 10));
        ruleMap.put("D0404", new DataAccessRule("D0404", DataAccessRule.INT_TYPE, 1, 40, 8));
        ruleMap.put("D0405", new DataAccessRule("D0405", DataAccessRule.INT_TYPE, 1, 5, 2));
        ruleMap.put("D0406", new DataAccessRule("D0406", DataAccessRule.INT_TYPE, 1, 40, 3));
        ruleMap.put("D0407", new DataAccessRule("D0407", DataAccessRule.INT_TYPE, 1, 30, 8));
        ruleMap.put("D0408", new DataAccessRule("D0408", DataAccessRule.INT_TYPE, 1, 8, 3));
        ruleMap.put("D0409", new DataAccessRule("D0409", DataAccessRule.INT_TYPE, 0, 1, 0));
        ruleMap.put("D0412", new DataAccessRule("D0412", DataAccessRule.INT_TYPE, 1, 20, 5));

        ruleMap.put("D0211", new DataAccessRule("D0211", DataAccessRule.INT_TYPE, 1, 72, 0));
        ruleMap.put("D0213", new DataAccessRule("D0213", DataAccessRule.INT_TYPE, 0, 2, 2));
        ruleMap.put("D0214", new DataAccessRule("D0214", DataAccessRule.INT_TYPE, 1, 72, 72));
        ruleMap.put("D0215", new DataAccessRule("D0215", DataAccessRule.INT_TYPE, 1, 72, 72));
        ruleMap.put("D0216", new DataAccessRule("D0216", DataAccessRule.INT_TYPE, 0, 1, 0));
        ruleMap.put("D0226", new DataAccessRule("D0226", DataAccessRule.INT_TYPE, 300, 1000, 500));

        ruleMap.put(MachineParameterSharedPreference.DOFFER_START_NUM,
                new DataAccessRule(MachineParameterSharedPreference.DOFFER_START_NUM,
                        DataAccessRule.INT_TYPE, 1, 72, 1));
        ruleMap.put(MachineParameterSharedPreference.DOFFER_RUN_STATUS,
                new DataAccessRule(MachineParameterSharedPreference.DOFFER_RUN_STATUS,
                        DataAccessRule.INT_TYPE, 0, 2, 0));

        ruleMap.put(MachineParameterSharedPreference.SPINDLE_ENDS_NUM,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_ENDS_NUM,
                        DataAccessRule.INT_TYPE, 1, 9, 1));
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_YARN_CODE,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_YARN_CODE,
                        DataAccessRule.INT_TYPE, 1, 10, 1));
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_PCF,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_PCF,
                        DataAccessRule.FLOAT_TYPE, 0.8f, 1.2f, "1", 1.0f));
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_SLIP,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_SLIP,
                        DataAccessRule.FLOAT_TYPE, 0.8f, 1.2f, "1", 1.0f));
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_PKG_WEI,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_PKG_WEI,
                        DataAccessRule.INT_TYPE, 13, 12000, 2599));//g
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_COP_WEI,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_COP_WEI,
                        DataAccessRule.INT_TYPE, 13, 120, 13));//g
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_SINGLE_STRENGTH,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_SINGLE_STRENGTH,
                        DataAccessRule.INT_TYPE, 1, 1000, 1));
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_COP_NUM,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_COP_NUM,
                        DataAccessRule.INT_TYPE, 1, 3, 3));
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_TENS_YARN_NUM,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_TENS_YARN_NUM,
                        DataAccessRule.INT_TYPE, 1, 50, 1));
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_SAMPLE_YARN_NUM,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_SAMPLE_YARN_NUM,
                        DataAccessRule.INT_TYPE, 1, 3, 1));
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_SAMPLE_UP_LMT,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_SAMPLE_UP_LMT,
                        DataAccessRule.INT_TYPE, 0, 100, 0));
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_SAMPLE_LOW_LMT,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_SAMPLE_LOW_LMT,
                        DataAccessRule.INT_TYPE, 0, 100, 0));
        ruleMap.put(MachineParameterSharedPreference.SPINDLE_PKG_LEN,
                new DataAccessRule(MachineParameterSharedPreference.SPINDLE_PKG_LEN,
                        DataAccessRule.INT_TYPE, 1000, 900000, 200000));
        ruleMap.put(MachineParameterSharedPreference.IN_SEGMENT_TIME1,
                new DataAccessRule(MachineParameterSharedPreference.IN_SEGMENT_TIME1, DataAccessRule.FLOAT_TYPE, 0.1f, 0.55f, "2", 0.1f));
        ruleMap.put(MachineParameterSharedPreference.IN_SEGMENT_TIME2,
                new DataAccessRule(MachineParameterSharedPreference.IN_SEGMENT_TIME2, DataAccessRule.FLOAT_TYPE, 0.1f, 0.55f, "2", 0.1f));

        ruleMap.put(String.valueOf(0x10) + "-" + 0,
                new DataAccessRule(String.valueOf(0x10) + "-" + 0, DataAccessRule.INT_TYPE, 3, 30, 10));
        ruleMap.put(String.valueOf(0x10) + "-" + 1,
                new DataAccessRule(String.valueOf(0x10) + "-" + 1, DataAccessRule.INT_TYPE, 3, 30, 10));
        ruleMap.put(String.valueOf(0x15) + "-" + 0,
                new DataAccessRule(String.valueOf(0x15) + "-" + 0, DataAccessRule.INT_TYPE, 0, 25, 0));
        ruleMap.put(String.valueOf(0x15) + "-" + 1,
                new DataAccessRule(String.valueOf(0x15) + "-" + 1, DataAccessRule.INT_TYPE, 0, 1, 0));
        ruleMap.put(String.valueOf(0x15) + "-" + 2,
                new DataAccessRule(String.valueOf(0x15) + "-" + 2, DataAccessRule.INT_TYPE, 0, 200, 5));
        ruleMap.put(String.valueOf(0x15) + "-" + 3,
                new DataAccessRule(String.valueOf(0x15) + "-" + 3, DataAccessRule.INT_TYPE, 0, 200, 5));
        ruleMap.put(String.valueOf(0x16) + "-" + 0,
                new DataAccessRule(String.valueOf(0x16) + "-" + 0, DataAccessRule.INT_TYPE, 0, 65535, 0));
        ruleMap.put(String.valueOf(0x16) + "-" + 1,
                new DataAccessRule(String.valueOf(0x16) + "-" + 1, DataAccessRule.INT_TYPE, 1, 50, 25));
        ruleMap.put(String.valueOf(0x16) + "-" + 2,
                new DataAccessRule(String.valueOf(0x16) + "-" + 2, DataAccessRule.INT_TYPE, 1, 5, 3));
        ruleMap.put(String.valueOf(0x16) + "-" + 3,
                new DataAccessRule(String.valueOf(0x16) + "-" + 3, DataAccessRule.INT_TYPE, 1, 5, 3));
        ruleMap.put(String.valueOf(0x16) + "-" + 4,
                new DataAccessRule(String.valueOf(0x16) + "-" + 4, DataAccessRule.INT_TYPE, 1, 50, 25));
        ruleMap.put(String.valueOf(0x20) + "-" + 0,
                new DataAccessRule(String.valueOf(0x20) + "-" + 0, DataAccessRule.INT_TYPE, 0, 2200, 1000));
        ruleMap.put(String.valueOf(0x20) + "-" + 1,
                new DataAccessRule(String.valueOf(0x20) + "-" + 1, DataAccessRule.INT_TYPE, 3, 30, 10));
        ruleMap.put(String.valueOf(0x20) + "-" + 2,
                new DataAccessRule(String.valueOf(0x20) + "-" + 2, DataAccessRule.INT_TYPE, 0, 1, 0));
        ruleMap.put(String.valueOf(0x20) + "-" + 3,
                new DataAccessRule(String.valueOf(0x20) + "-" + 3, DataAccessRule.INT_TYPE, 0, 1, 0));


        ruleMap.put(String.valueOf(0x21) + "-" + 0,
                new DataAccessRule(String.valueOf(0x21) + "-" + 0, DataAccessRule.INT_TYPE, 10, 70, 60));
        ruleMap.put(String.valueOf(0x21) + "-" + 1,
                new DataAccessRule(String.valueOf(0x21) + "-" + 1, DataAccessRule.INT_TYPE, 50, 110, 80));
        ruleMap.put(String.valueOf(0x21) + "-" + 3,
                new DataAccessRule(String.valueOf(0x21) + "-" + 3, DataAccessRule.INT_TYPE, 0, 8, 3));//DC.H
        ruleMap.put(String.valueOf(0x21) + "-" + 2,
                new DataAccessRule(String.valueOf(0x21) + "-" + 2, DataAccessRule.INT_TYPE, 0, 8, 3));//DC.L

        ruleMap.put(String.valueOf(0x22) + "-" + 0,
                new DataAccessRule(String.valueOf(0x22) + "-" + 0, DataAccessRule.INT_TYPE, 1, 5, 3));
        ruleMap.put(String.valueOf(0x22) + "-" + 1,
                new DataAccessRule(String.valueOf(0x22) + "-" + 1, DataAccessRule.INT_TYPE, 1, 3, 3));
        ruleMap.put(String.valueOf(0x22) + "-" + 2,
                new DataAccessRule(String.valueOf(0x22) + "-" + 2, DataAccessRule.INT_TYPE, 1, 3, 3));

        ruleMap.put(String.valueOf(0x23) + "-" + 0,
                new DataAccessRule(String.valueOf(0x23) + "-" + 0, DataAccessRule.INT_TYPE, 1200, 5000, 1600));
        String key = String.valueOf(0x20) + "-" + "0";
        int spd = Integer.valueOf(sp.getValue(1, key, "0"));//等待分组做好之后，更改当前选定组号grp_select
        if (spd <= 1200) {
            ruleMap.put(String.valueOf(0x23) + "-" + 2,
                    new DataAccessRule(String.valueOf(0x23) + "-" + 2, DataAccessRule.INT_TYPE, 1, 15, 10));//速度增加 DC.H
        } else if (spd > 1200 && spd <= 1400) {
            ruleMap.put(String.valueOf(0x23) + "-" + 2,
                    new DataAccessRule(String.valueOf(0x23) + "-" + 2, DataAccessRule.INT_TYPE, 1, 14, 10));//速度增加
        } else if (spd > 1400) {
            ruleMap.put(String.valueOf(0x23) + "-" + 2,
                    new DataAccessRule(String.valueOf(0x23) + "-" + 2, DataAccessRule.INT_TYPE, 1, 12, 10));//速度增加
        }

        ruleMap.put(String.valueOf(0x23) + "-" + 1,
                new DataAccessRule(String.valueOf(0x23) + "-" + 1, DataAccessRule.INT_TYPE, 1, 60, 25));//DC.L
        ruleMap.put(String.valueOf(0x23) + "-" + 3,
                new DataAccessRule(String.valueOf(0x23) + "-" + 3, DataAccessRule.INT_TYPE, 0, 1, 0));//0xaa=170 防叠方式？

        ruleMap.put(String.valueOf(0x24) + "-" + 0,
                new DataAccessRule(String.valueOf(0x24) + "-" + 0, DataAccessRule.INT_TYPE, 1, 900000, 200000));
        ruleMap.put(String.valueOf(0x24) + "-" + 1,
                new DataAccessRule(String.valueOf(0x24) + "-" + 1, DataAccessRule.INT_TYPE, 1000, 9000, 1000));
        ruleMap.put(String.valueOf(0x24) + "-" + 2,
                new DataAccessRule(String.valueOf(0x24) + "-" + 2, DataAccessRule.FLOAT_TYPE, 1.000f, 9.000f, "3", 9216));

        ruleMap.put(String.valueOf(0x25) + "-" + 0,
                new DataAccessRule(String.valueOf(0x25) + "-" + 0, DataAccessRule.INT_TYPE, 1, 5000, 250));
        ruleMap.put(String.valueOf(0x25) + "-" + 1,
                new DataAccessRule(String.valueOf(0x25) + "-" + 1, DataAccessRule.INT_TYPE, 1, 100, 50));
        ruleMap.put(String.valueOf(0x25) + "-" + 2,
                new DataAccessRule(String.valueOf(0x25) + "-" + 2, DataAccessRule.INT_TYPE, 50, 1000, 50));

        ruleMap.put(String.valueOf(0x26) + "-" + 0,
                new DataAccessRule(String.valueOf(0x26) + "-" + 0, DataAccessRule.INT_TYPE, 50, 100, 100));
        ruleMap.put(String.valueOf(0x26) + "-" + 1,
                new DataAccessRule(String.valueOf(0x26) + "-" + 1, DataAccessRule.INT_TYPE, 0, 90, 0));
        ruleMap.put(String.valueOf(0x26) + "-" + 2,
                new DataAccessRule(String.valueOf(0x26) + "-" + 2, DataAccessRule.INT_TYPE, 1, 64, 1));//	64=1<<6

        ruleMap.put(String.valueOf(0x27) + "-" + 1,
                new DataAccessRule(String.valueOf(0x27) + "-" + 1, DataAccessRule.INT_TYPE, 0, 100, 0));
        ruleMap.put(String.valueOf(0x27) + "-" + 0,
                new DataAccessRule(String.valueOf(0x27) + "-" + 0, DataAccessRule.INT_TYPE, 0, 0x55, 0));
        ruleMap.put(String.valueOf(0x27) + "-" + 3,
                new DataAccessRule(String.valueOf(0x27) + "-" + 3, DataAccessRule.INT_TYPE, 0, 100, 50));
        ruleMap.put(String.valueOf(0x27) + "-" + 2,
                new DataAccessRule(String.valueOf(0x27) + "-" + 2, DataAccessRule.INT_TYPE, 0, 100, 20));
        ruleMap.put(String.valueOf(0x27) + "-" + 5,
                new DataAccessRule(String.valueOf(0x27) + "-" + 5, DataAccessRule.INT_TYPE, 0, 100, 0));
        ruleMap.put(String.valueOf(0x27) + "-" + 4,
                new DataAccessRule(String.valueOf(0x27) + "-" + 4, DataAccessRule.INT_TYPE, 0, 100, 0));

        ruleMap.put(String.valueOf(0x28) + "-" + 0,
                new DataAccessRule(String.valueOf(0x28) + "-" + 0, DataAccessRule.INT_TYPE, 50, 2200, 800));
        ruleMap.put(String.valueOf(0x28) + "-" + 1,
                new DataAccessRule(String.valueOf(0x28) + "-" + 1, DataAccessRule.FLOAT_TYPE, 0.1f, 200.0f, "1", 45.0f));
        ruleMap.put(String.valueOf(0x28) + "-" + 2,
                new DataAccessRule(String.valueOf(0x28) + "-" + 2, DataAccessRule.INT_TYPE, 3, 30, 10));

        ruleMap.put(String.valueOf(0x29) + "-" + 0,
                new DataAccessRule(String.valueOf(0x29) + "-" + 0, DataAccessRule.INT_TYPE, 0, 9029, 9029));//length pulse
        ruleMap.put(String.valueOf(0x29) + "-" + 1,
                new DataAccessRule(String.valueOf(0x29) + "-" + 1, DataAccessRule.INT_TYPE, 1, 72, 20));

        ruleMap.put(String.valueOf(0x2a) + "-" + 0,
                new DataAccessRule(String.valueOf(0x2a) + "-" + 0, DataAccessRule.INT_TYPE, 0, 49, 25));
        ruleMap.put(String.valueOf(0x2a) + "-" + 1,
                new DataAccessRule(String.valueOf(0x2a) + "-" + 1, DataAccessRule.INT_TYPE, 0, 49, 25));

        ruleMap.put(String.valueOf(0x2c) + "-" + 0,
                new DataAccessRule(String.valueOf(0x2c) + "-" + 0, DataAccessRule.INT_TYPE, 1, 12, 2));
        ruleMap.put(String.valueOf(0x2c) + "-" + 1,
                new DataAccessRule(String.valueOf(0x2c) + "-" + 1, DataAccessRule.INT_TYPE, 1, 12, 3));
        ruleMap.put(String.valueOf(0x2c) + "-" + 2,
                new DataAccessRule(String.valueOf(0x2c) + "-" + 2, DataAccessRule.INT_TYPE, 1, 12, 4));

        ruleMap.put(String.valueOf(0x2e) + "-" + 0,
                new DataAccessRule(String.valueOf(0x2e) + "-" + 0, DataAccessRule.INT_TYPE, 0, 150, 55));
        ruleMap.put(String.valueOf(0x2e) + "-" + 1,
                new DataAccessRule(String.valueOf(0x2e) + "-" + 1, DataAccessRule.INT_TYPE, 0, 10000, 0));
        ruleMap.put(String.valueOf(0x2e) + "-" + 2,
                new DataAccessRule(String.valueOf(0x2e) + "-" + 2, DataAccessRule.INT_TYPE, 0, 10000, 0));

        ruleMap.put(String.valueOf(0x30) + "-" + 0,
                new DataAccessRule(String.valueOf(0x30) + "-" + 0, DataAccessRule.INT_TYPE, 0, 10000, 0));

        ruleMap.put(String.valueOf(0x39) + "-" + 0,
                new DataAccessRule(String.valueOf(0x39) + "-" + 0, DataAccessRule.INT_TYPE, 0, 30, 0));
        ruleMap.put(String.valueOf(0x39) + "-" + 1,
                new DataAccessRule(String.valueOf(0x39) + "-" + 1, DataAccessRule.INT_TYPE, 0, 1, 0));

        ruleMap.put(String.valueOf(0x40) + "-" + 0,
                new DataAccessRule(String.valueOf(0x40) + "-" + 0, DataAccessRule.INT_TYPE, 0, 10000, 0));
        //查询参数
        ruleMap.put(String.valueOf(0x10 << 8 | 0),
                new DataAccessRule(String.valueOf(0x20 << 8 | 0), DataAccessRule.INT_TYPE, 3, 30, 10));
        ruleMap.put(String.valueOf(0x10 << 8 | 1),
                new DataAccessRule(String.valueOf(0x20 << 8 | 1), DataAccessRule.INT_TYPE, 3, 30, 10));

        ruleMap.put(String.valueOf(0x20 << 8 | 0),
                new DataAccessRule(String.valueOf(0x20 << 8 | 0), DataAccessRule.INT_TYPE, 0, 2200, 1000));
        ruleMap.put(String.valueOf(0x20 << 8 | 1),
                new DataAccessRule(String.valueOf(0x20 << 8 | 1), DataAccessRule.INT_TYPE, 3, 30, 10));
        ruleMap.put(String.valueOf(0x20 << 8 | 2),
                new DataAccessRule(String.valueOf(0x20 << 8 | 2), DataAccessRule.FLOAT_TYPE, 2.0f, 2.5f, "1", 2.0f));
        ruleMap.put(String.valueOf(0x20 << 8 | 3),
                new DataAccessRule(String.valueOf(0x20 << 8 | 3), DataAccessRule.INT_TYPE, 0, 1, 0));

        ruleMap.put(String.valueOf(0x21 << 8 | 0),
                new DataAccessRule(String.valueOf(0x21 << 8 | 0), DataAccessRule.INT_TYPE, 10, 70, 60));
        ruleMap.put(String.valueOf(0x21 << 8 | 1),
                new DataAccessRule(String.valueOf(0x21 << 8 | 1), DataAccessRule.INT_TYPE, 50, 110, 80));
        ruleMap.put(String.valueOf(0x21 << 8 | 3),
                new DataAccessRule(String.valueOf(0x21 << 8 | 3), DataAccessRule.INT_TYPE, 0, 8, 3));//DC.H
        ruleMap.put(String.valueOf(0x21 << 8 | 2),
                new DataAccessRule(String.valueOf(0x21 << 8 | 2), DataAccessRule.INT_TYPE, 0, 8, 3));//DC.L

        ruleMap.put(String.valueOf(0x22 << 8 | 0),
                new DataAccessRule(String.valueOf(0x22 << 8 | 0), DataAccessRule.INT_TYPE, 1, 5, 3));
        ruleMap.put(String.valueOf(0x22 << 8 | 1),
                new DataAccessRule(String.valueOf(0x22 << 8 | 1), DataAccessRule.INT_TYPE, 1, 3, 3));
        ruleMap.put(String.valueOf(0x22 << 8 | 2),
                new DataAccessRule(String.valueOf(0x22 << 8 | 2), DataAccessRule.INT_TYPE, 1, 3, 3));

        ruleMap.put(String.valueOf(0x23 << 8 | 0),
                new DataAccessRule(String.valueOf(0x23 << 8 | 0), DataAccessRule.INT_TYPE, 1200, 5000, 1600));
        ruleMap.put(String.valueOf(0x23 << 8 | 2),
                new DataAccessRule(String.valueOf(0x23 << 8 | 2), DataAccessRule.INT_TYPE, 1, 15, 10));//速度增加 DC.H

        ruleMap.put(String.valueOf(0x23 << 8 | 1),
                new DataAccessRule(String.valueOf(0x23 << 8 | 1), DataAccessRule.INT_TYPE, 1, 60, 25));//DC.L
        ruleMap.put(String.valueOf(0x23 << 8 | 3),
                new DataAccessRule(String.valueOf(0x23 << 8 | 3), DataAccessRule.INT_TYPE, 0, 170, 0));//0xaa=170

        ruleMap.put(String.valueOf(0x24 << 8 | 0),
                new DataAccessRule(String.valueOf(0x24 << 8 | 0), DataAccessRule.INT_TYPE, 1000, 900000, 200000));
        ruleMap.put(String.valueOf(0x24 << 8 | 1),
                new DataAccessRule(String.valueOf(0x24 << 8 | 1), DataAccessRule.INT_TYPE, 1000, 9000, 1000));
        ruleMap.put(String.valueOf(0x24 << 8 | 2),
                new DataAccessRule(String.valueOf(0x24 << 8 | 2), DataAccessRule.FLOAT_TYPE, 1.000f, 9.000f, "3", 9.000f));

        ruleMap.put(String.valueOf(0x25 << 8 | 0),
                new DataAccessRule(String.valueOf(0x25 << 8 | 0), DataAccessRule.INT_TYPE, 1, 5000, 250));
        ruleMap.put(String.valueOf(0x25 << 8 | 1),
                new DataAccessRule(String.valueOf(0x25 << 8 | 1), DataAccessRule.INT_TYPE, 1, 100, 50));
        ruleMap.put(String.valueOf(0x25 << 8 | 2),
                new DataAccessRule(String.valueOf(0x25 << 8 | 2), DataAccessRule.INT_TYPE, 50, 1000, 50));

        ruleMap.put(String.valueOf(0x26 << 8 | 0),
                new DataAccessRule(String.valueOf(0x26 << 8 | 0), DataAccessRule.INT_TYPE, 50, 100, 100));
        ruleMap.put(String.valueOf(0x26 << 8 | 1),
                new DataAccessRule(String.valueOf(0x26 << 8 | 1), DataAccessRule.INT_TYPE, 0, 90, 0));
        ruleMap.put(String.valueOf(0x26 << 8 | 2),
                new DataAccessRule(String.valueOf(0x26 << 8 | 2), DataAccessRule.INT_TYPE, 1, 64, 1));//	64=1<<6

        ruleMap.put(String.valueOf(0x27 << 8 | 1),
                new DataAccessRule(String.valueOf(0x27 << 8 | 1), DataAccessRule.INT_TYPE, 0, 100, 0));
        ruleMap.put(String.valueOf(0x27 << 8 | 0),
                new DataAccessRule(String.valueOf(0x27 << 8 | 0), DataAccessRule.INT_TYPE, 0, 0x55, 0));
        ruleMap.put(String.valueOf(0x27 << 8 | 3),
                new DataAccessRule(String.valueOf(0x27 << 8 | 3), DataAccessRule.INT_TYPE, 0, 100, 50));
        ruleMap.put(String.valueOf(0x27 << 8 | 2),
                new DataAccessRule(String.valueOf(0x27 << 8 | 2), DataAccessRule.INT_TYPE, 0, 100, 20));
        ruleMap.put(String.valueOf(0x27 << 8 | 5),
                new DataAccessRule(String.valueOf(0x27 << 8 | 5), DataAccessRule.INT_TYPE, 0, 100, 0));
        ruleMap.put(String.valueOf(0x27 << 8 | 4),
                new DataAccessRule(String.valueOf(0x27 << 8 | 4), DataAccessRule.INT_TYPE, 0, 100, 0));

        ruleMap.put(String.valueOf(0x28 << 8 | 0),
                new DataAccessRule(String.valueOf(0x28 << 8 | 0), DataAccessRule.INT_TYPE, 50, 2200, 800));
        ruleMap.put(String.valueOf(0x28 << 8 | 1),
                new DataAccessRule(String.valueOf(0x28 << 8 | 1), DataAccessRule.FLOAT_TYPE, 0.1f, 200.0f, "1", 45.0f));
        ruleMap.put(String.valueOf(0x28 << 8 | 2),
                new DataAccessRule(String.valueOf(0x28 << 8 | 2), DataAccessRule.INT_TYPE, 3, 30, 10));

        ruleMap.put(String.valueOf(0x29 << 8 | 0),
                new DataAccessRule(String.valueOf(0x29 << 8 | 0), DataAccessRule.INT_TYPE, 0, 9029, 9029));//length pulse
        ruleMap.put(String.valueOf(0x29 << 8 | 1),
                new DataAccessRule(String.valueOf(0x29 << 8 | 1), DataAccessRule.INT_TYPE, 1, 72, 20));
        ruleMap.put(String.valueOf(0x29 << 8 | 2),
                new DataAccessRule(String.valueOf(0x29 << 8 | 2), DataAccessRule.FLOAT_TYPE, 0.0f, Float.MAX_VALUE, "2", 0.0f));

        ruleMap.put(String.valueOf(0x2a << 8 | 0),
                new DataAccessRule(String.valueOf(0x2a << 8 | 0), DataAccessRule.INT_TYPE, 0, 49, 25));
        ruleMap.put(String.valueOf(0x2a << 8 | 1),
                new DataAccessRule(String.valueOf(0x2a << 8 | 1), DataAccessRule.INT_TYPE, 0, 49, 25));

        ruleMap.put(String.valueOf(0x2C << 8 | 0),
                new DataAccessRule(String.valueOf(0x2C << 8 | 0), DataAccessRule.INT_TYPE, 1, 1, 2));
        ruleMap.put(String.valueOf(0x2C << 8 | 1),
                new DataAccessRule(String.valueOf(0x2C << 8 | 1), DataAccessRule.INT_TYPE, 1, 12, 3));
        ruleMap.put(String.valueOf(0x2C << 8 | 2),
                new DataAccessRule(String.valueOf(0x2C << 8 | 2), DataAccessRule.INT_TYPE, 1, 12, 4));


        ruleMap.put(String.valueOf(0x30 << 8 | 0),
                new DataAccessRule(String.valueOf(0x30 << 8 | 0), DataAccessRule.INT_TYPE, 0, 65535, 0));
        ruleMap.put(String.valueOf(0x30 << 8 | 1),
                new DataAccessRule(String.valueOf(0x30 << 8 | 1), DataAccessRule.INT_TYPE, 0, 65535, 0));
        ruleMap.put(String.valueOf(0x30 << 8 | 2),
                new DataAccessRule(String.valueOf(0x30 << 8 | 2), DataAccessRule.INT_TYPE, 0, 65535, 0));

        ruleMap.put(String.valueOf(0x31 << 8 | 0),
                new DataAccessRule(String.valueOf(0x31 << 8 | 0), DataAccessRule.INT_TYPE, 0, 65535, 0));
//		ruleMap.put(String.valueOf(0x31 << 8 | 1),
//				new DataAccessRule(String.valueOf(0x31 << 8 | 1), DataAccessRule.INT_TYPE, 0, 65535, 0));
        ruleMap.put(String.valueOf(0x31 << 8 | 2),
                new DataAccessRule(String.valueOf(0x31 << 8 | 2), DataAccessRule.INT_TYPE, 0, 65535, 0));

        ruleMap.put(String.valueOf(0x32 << 8 | 0),
                new DataAccessRule(String.valueOf(0x32 << 8 | 0), DataAccessRule.INT_TYPE, 0, 65535, 0));
        ruleMap.put(String.valueOf(0x32 << 8 | 1),
                new DataAccessRule(String.valueOf(0x32 << 8 | 1), DataAccessRule.INT_TYPE, 0, 65535, 0));
        ruleMap.put(String.valueOf(0x32 << 8 | 2),
                new DataAccessRule(String.valueOf(0x32 << 8 | 2), DataAccessRule.INT_TYPE, 0, 65535, 0));

        ruleMap.put(String.valueOf(0x33 << 8 | 0),
                new DataAccessRule(String.valueOf(0x33 << 8 | 0), DataAccessRule.INT_TYPE, 0, 65535, 0));
        ruleMap.put(String.valueOf(0x33 << 8 | 1),
                new DataAccessRule(String.valueOf(0x33 << 8 | 1), DataAccessRule.INT_TYPE, 0, 65535, 0));
        ruleMap.put(String.valueOf(0x33 << 8 | 2),
                new DataAccessRule(String.valueOf(0x33 << 8 | 2), DataAccessRule.INT_TYPE, 0, 65535, 0));
        keySet = new LinkedHashSet<String>();
        keySet.add(COL_TIME);
        keySet.add(COL_NAME);
        keySet.add(COL_CATEGORY);
        keySet.addAll(ruleMap.keySet());

        nameMap = new LinkedHashMap<String, Integer>();
        nameMap.put(String.valueOf(0x10 << 8 | 0), R.string.acc_time_big);
        nameMap.put(String.valueOf(0x10 << 8 | 1), R.string.acc_time_small);
        nameMap.put(String.valueOf(0x20 << 8 | 0), R.string.single_doffer_speed);
        nameMap.put(String.valueOf(0x20 << 8 | 1), R.string.acc_time_middle);
        nameMap.put(String.valueOf(0x20 << 8 | 2), R.string.helix_num);
        nameMap.put(String.valueOf(0x20 << 8 | 3), R.string.tension_pad_type);
        nameMap.put(String.valueOf(0x21 << 8 | 0), R.string.s_drum_rev_spd);
        nameMap.put(String.valueOf(0x21 << 8 | 1), R.string.l_drum_rev_spd);
        nameMap.put(String.valueOf(0x21 << 8 | 2), R.string.cop_auto_start);
        nameMap.put(String.valueOf(0x21 << 8 | 3), R.string.splice_auto_start);
        nameMap.put(String.valueOf(0x22 << 8 | 0), R.string.cycle_num);
        nameMap.put(String.valueOf(0x22 << 8 | 1), R.string.pkg_num);
        nameMap.put(String.valueOf(0x22 << 8 | 2), R.string.change_num);
        nameMap.put(String.valueOf(0x23 << 8 | 0), R.string.anti_ptn_period);
        nameMap.put(String.valueOf(0x23 << 8 | 1), R.string.acc_time_per);
        nameMap.put(String.valueOf(0x23 << 8 | 2), R.string.acc_spd);
        nameMap.put(String.valueOf(0x23 << 8 | 3), R.string.anti_ptn_mode);
        nameMap.put(String.valueOf(0x24 << 8 | 0), R.string.pkg_len);
        nameMap.put(String.valueOf(0x24 << 8 | 1), R.string.cop_len);
        nameMap.put(String.valueOf(0x24 << 8 | 2), R.string.package_diameter);
        nameMap.put(String.valueOf(0x25 << 8 | 0), R.string.max_pkg_splice);
        nameMap.put(String.valueOf(0x25 << 8 | 1), R.string.max_cop_cuts);
        nameMap.put(String.valueOf(0x25 << 8 | 2), R.string.blow_time);
        nameMap.put(String.valueOf(0x26 << 8 | 0), R.string.yarn_len);
        nameMap.put(String.valueOf(0x26 << 8 | 1), R.string.spd_reduce);
        nameMap.put(String.valueOf(0x26 << 8 | 2), R.string.anti_wrap_sense);
        nameMap.put(String.valueOf(0x27 << 8 | 0), R.string.tens_sensor);
        nameMap.put(String.valueOf(0x27 << 8 | 1), R.string.min_tens);
        nameMap.put(String.valueOf(0x27 << 8 | 2), R.string.tens_increase);
        nameMap.put(String.valueOf(0x27 << 8 | 3), R.string.tension_value);
        nameMap.put(String.valueOf(0x27 << 8 | 4), R.string.tens_up_lmt);
        nameMap.put(String.valueOf(0x27 << 8 | 5), R.string.tens_low_lmt);
        nameMap.put(String.valueOf(0x28 << 8 | 0), R.string.pkg_init_spd);
        nameMap.put(String.valueOf(0x28 << 8 | 1), R.string.yarn_cnt);
        nameMap.put(String.valueOf(0x28 << 8 | 2), R.string.slow_brake_dec_time);
        nameMap.put(String.valueOf(0x29 << 8 | 0), R.string.current_can_length);
        nameMap.put(String.valueOf(0x29 << 8 | 1), R.string.current_cop_length);
        nameMap.put(String.valueOf(0x29 << 8 | 2), R.string.tube_diameter_ratio);
        nameMap.put(String.valueOf(0x2A << 8 | 0), R.string.over_spd_inc);
        nameMap.put(String.valueOf(0x2A << 8 | 1), R.string.no_over_cycle_inc);
        nameMap.put(String.valueOf(0x2C << 8 | 0), R.string.splicer_time_t1);
        nameMap.put(String.valueOf(0x2C << 8 | 1), R.string.splicer_time_t2);
        nameMap.put(String.valueOf(0x2C << 8 | 2), R.string.splicer_length);
        nameMap.put(String.valueOf(0x30 << 8 | 0), R.string.spindle_warn_fault1);
        nameMap.put(String.valueOf(0x30 << 8 | 1), R.string.clearers_alarm);
        nameMap.put(String.valueOf(0x30 << 8 | 2), R.string.spindle_warn_fault2);
        nameMap.put(String.valueOf(0x31 << 8 | 0), R.string.spindle_logic_control_warn);
        nameMap.put(String.valueOf(0x31 << 8 | 2), R.string.input_warn);
        nameMap.put(String.valueOf(0x32 << 8 | 0), R.string.driver_warn1);
        nameMap.put(String.valueOf(0x32 << 8 | 1), R.string.driver_warn2);
        nameMap.put(String.valueOf(0x32 << 8 | 2), R.string.SCI_communintcation_state);
        nameMap.put(String.valueOf(0x33 << 8 | 0), R.string.DSP_version);
        nameMap.put(String.valueOf(0x33 << 8 | 1), R.string.FPGA_version);
        nameMap.put(String.valueOf(0x33 << 8 | 2), R.string.CAN_fault_register_state);
        unitMap = new HashMap<String, Integer>();
    }

    ;

    public static SmaroWindingMachineDataAccessRules getInstance() {
        return rules;
    }

    public DataAccessRule getDataAccessRule(String key) {
        return ruleMap.get(key);
    }

    public boolean isBetween(String key, String value) {
        return ruleMap.get(key).isBetween(value);
    }

    public Set<String> getKeySet() {
        return keySet;
    }

    public String getName(String key) {
        Integer resId = nameMap.get(key);
        if (resId != null) {
            return AppContext.getInstance().getResources().getString(resId);
        } else {
            return "null";
        }
    }

    public String getUnit(String key) {
        Integer resId = unitMap.get(key);
        if (resId != null) {
            return AppContext.getInstance().getResources().getString(resId);
        } else {
            return "";
        }
    }
}
